package com.company;

public class Main {

    public static void rotate(int[][] matrix) {
        int len = matrix.length;
        int step = len / 2;
        int[] temp = new int[4];
        for (int j = 0; j < step; j++) {
            for (int i = 0; i < len - 1-j*2; i++) {
                temp[0] = matrix[j][j + i];
                temp[1] = matrix[j + i][len - 1 - j];
                temp[2] = matrix[len - 1 - j][len - 1 - j - i];
                temp[3] = matrix[len - 1 - j - i][j];

                matrix[j][j + i] = temp[3];
                matrix[j + i][len - 1 - j] = temp[0];
                matrix[len - 1 - j][len - 1 - j - i] = temp[1];
                matrix[len - 1 - j - i][j] = temp[2];
            }

        }
    }

    public static void main(String[] args) {
	// write your code here
        int[][]matrix={
                {5, 1, 9,11},
                {2, 4, 8,10},
                {13, 3, 6, 7},
                {15,14,12,16}
        };

        rotate(matrix);

        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                System.out.print(matrix[i][j]+",");
            }
            System.out.println("\n");
        }
        //ystem.out.println(matrix.length);
    }
}
